<?php
/**
 * AccountAgentTradeLogsList
 *
 * @package Akimimi front
 * @author by M.Wang
 */

require_once '../app/views/BaseView.php';
class AccountAgentTradeLogsListView extends BaseView {

    public $logs;
    public $pager;
    public $tradetypes;
    public $formdata = array(
        'page' => 1,
        'sn' => '',
        'createdd' => '',
        'createdu' => ''
    );
    public $action = '/trade/supplementlogs/';
    public $detailAction = '/trade/tradeloginfo/';

    public function getPage(){
        $arr_navsetting = array(
            array('url'=>'/userinfo/index', 'text'=>MYAKIMIMITXT),
            array('text'=>'安全账户清单')
        );
        $this->setPageTitle('安全账户清单');
        $this->addCSS('tradelog.css');
        $this->addCSS('myaccountleftnav.css');
        $this->addCSS('jquery.ui.css');
        $this->addJS('lib/ui.core.js',true);
        $this->addJS('lib/jquery-ui-datepicker.js',true);
        $str_js = "
            <script type='text/javascript'>
            $(document).ready(function() {
                $('#log_createdd').datepicker({
                    changeMonth: true,
                    changeYear: true,
                    dateFormat: 'yy-mm-dd'
                });
                $('#log_createdu').datepicker({
                    changeMonth: true,
                    changeYear: true,
                    dateFormat: 'yy-mm-dd'
                });
            });
            </script>";
        $this->setHeadExtends($str_js);
        $header = '';
        require_once '../app/views/MyAccoutLeftNavView.php';
        $myAccountLeftNavView = new MyAccountLeftNav();
        $str_result = $header
                    . $this->getNavigation($arr_navsetting)
                    . "<div id='mymimi_body'>"
                    . $myAccountLeftNavView->getMyAccountLeftNav()
                    . $this->getContent()
                    . '</div>';
        return $this->getHtmlPage($str_result);
    }

    public function getContent(){
        return "<div id='mymimi_right'><div class='right_bj'></div>"
               . "<div id='coupons_list'>"
               . $this->getSearchBlock()
               . $this->getGrid()
               . '</div></div>';
    }

    public function getGrid(){
        $str_table = $this->getTableHead() . $this->getTableBody() . $this->getTableFooter();
    	$str_result = "<table cellpadding='1' cellspacing='0' style='margin:18px auto auto auto;width:99%;line-height:24px;border-collapse:collapse;font-size:11px;border:1px solid #999;'>{$str_table}</table>";
        return $str_result;
    }

    protected function getTableHead(){
        return "<thead><tr>"
               . "<th style='border:1px solid #999;font-size:12px;'>流水号</th>"
               . "<th style='border:1px solid #999;font-size:12px;'>交易类型</th>"
               . "<th style='border:1px solid #999;font-size:12px;'>交易<br />金额</th>"
               . "<th style='border:1px solid #999;font-size:12px;'>账户<br />余额<br />变更</th>"
               . "<th style='border:1px solid #999;font-size:12px;'>当前<br />账户<br />余额</th>"
               . "<th style='border:1px solid #999;font-size:12px;'>赊账<br />金额<br />变更</th>"
               . "<th style='border:1px solid #999;font-size:12px;'>当前<br />赊账<br />金额</th>"
               . "<th style='border:1px solid #999;font-size:12px;'>冻结<br />资金<br />变更</th>"
               . "<th style='border:1px solid #999;font-size:12px;'>当前<br />冻结<br />资金</th>"
               . "<th style='border:1px solid #999;font-size:12px;'>可用<br />金额<br />变更</th>"
               . "<th style='border:1px solid #999;font-size:12px;'>当前<br />可用<br />金额</th>"
               . "<th style='border:1px solid #999;font-size:12px;'>交易时间</th>"
               . '</tr></thead>';
    }

    protected function getTableBody(){
        if (empty($this->logs))
            return '';
        $str_result = '<tbody>';
        foreach ($this->logs as $int_key => $arr_log) {
        	if( $int_key % 2 )
        	   $str_bg = 'background-color:#f3f3f3;';
            else
                $str_bg = '';
            $str_result.= "<tr>"
                        . "<td style='border:1px solid #999;text-align:center;{$str_bg}'>" . (($arr_log['trade_type']=='1'||$arr_log['trade_type']=='3')?"<a href='/trade/tradeloginfo/{$arr_log['id']}'>{$arr_log['sn']}</a>":$arr_log['sn']) . '</td>'
                        . "<td style='border:1px solid #999;text-align:center;font-size:12px;{$str_bg}'>" . constant('AATLTRADETYPELIST'.$arr_log['trade_type']) . '</td>'
                        . "<td style='border:1px solid #999;text-align:right;{$str_bg}'><b>" . $arr_log['trade_sum'] . '</b></td>'
                        . "<td style='border:1px solid #999;text-align:right;{$str_bg}'>" . $this->formatMoneyField($arr_log['account_balance_offset']) . '</td>'
                        . "<td style='border:1px solid #999;text-align:right;color:#000;{$str_bg}'>" . $arr_log['balance_now'] . '</td>'
                        . "<td style='border:1px solid #999;text-align:right;{$str_bg}'>" . $this->formatMoneyField($arr_log['account_debt_balance_offset']) . '</td>'
                        . "<td style='border:1px solid #999;text-align:right;color:#000;{$str_bg}'>" . $arr_log['debt_now'] . '</td>'
                        . "<td style='border:1px solid #999;text-align:right;{$str_bg}'>" . $this->formatMoneyField($arr_log['account_freeze_offset']) . '</td>'
                        . "<td style='border:1px solid #999;text-align:right;color:#000;{$str_bg}'>" . $arr_log['freeze_now'] . '</td>'
                        . "<td style='border:1px solid #999;text-align:right;{$str_bg}'>" . $this->formatMoneyField($arr_log['account_usage_balance_offset']) . '</td>'
                        . "<td style='border:1px solid #999;text-align:right;color:#000;{$str_bg}'>" . $arr_log['usage_balance_now'] . '</td>'
                        . "<td style='border:1px solid #999;text-align:center;{$str_bg}'>" . $arr_log['created'] . '</td>'
                        . '</tr>';
        }
        return $str_result . '</tbody>';
    }

    protected function formatMoneyField($int_money){
    	if(empty($int_money)||$int_money == '0.00')
    	   return "<span style='color:#999;'>0.00</span>";
        if($int_money > 0)
           return "<span style='color:#090;'>{$int_money}</span>";
        if($int_money < 0)
           return "<span style='color:#900;'>{$int_money}</span>";
    }

    protected function getTableFooter(){
        if (empty($this->logs))
            return '';
        return "<tfoot><tr><td colspan='12'><div class='coupons_row_1'><div class='p2_page'>" . $this->getPager() . '</div></div></td></tr></tfoot>';
    }

    protected function getPager(){
        $pager = new Pager('searchTradeLogsForm','pageNumber',true);
        return $pager->paginate($this->formdata['page'], $this->pager['countrows'], $this->action );
    }

    protected function getSearchBlock(){
        $str_result = "<form id='searchTradeLogsForm' method='post' action='/trade/mytradelogs'>"
               . "<input type='hidden' id='pageNumber' name='page' value='{$this->formdata['page']}' />"
               . "<div class='order_row'><ul>";
        $str_result.= "<li style='width: 100px; text-align: center;'>" . '交易时间由：' . '</li>'
               . "<li style='width:90px;'><input id='log_createdd' style='width:90px;' type='text' name='createdd' value='{$this->formdata['createdd']}' /></li>"
               . "<li style='width: 30px; text-align: center;'>" . '&nbsp;至：&nbsp;' . '</li>'
               . "<li style='width:90px;'><input id='log_createdu' style='width:90px;' type='text' name='createdu' value='{$this->formdata['createdu']}' /></li>"
               . "<li style='width: 60px; text-align: center;'>" . '交易类型：' . '</li>'
               . "<li style='width:110px;'>" . $this->getTradeType($this->formdata['trade_type']) . '</li>'
               . "<li style='margin-left:20px;'><input type='submit' value=' " . OLSSUBMITBTN . " ' /></li>";
        $str_result.= '</ul></div></form>';
        return $str_result;
    }

    protected function getTradeType($int_type){
        $str_result = "<option value=''>" . '选择交易类型' . '</option>';
        foreach ($this->tradetypes as $int_key => $str_value) {
            if( $int_key < 1 )
                continue;
            $str_result.= "<option value='{$int_key}' " . ($int_type == $int_key ? "selected='selected'" : '') . ">{$str_value}</option>";
        }
        return "<select name='trade_type'>{$str_result}</select>";
    }

}
?>